/**
 * Created by IntelliJ IDEA.
 * User: maticm
 * Date: Oct 11, 2003
 * Time: 2:11:10 PM
 * To change this template use Options | File Templates.
 */

package com.generalynx.common.web.navigation;

import com.generalynx.common.web.module.Module;

public class TopMenuTextItemRenderer extends BasicMenuItemRenderer {

    private int m_iMenuItem;

    public TopMenuTextItemRenderer() {
        m_iMenuItem = 0;
    }

    public String permittedItem(Module node) {
        m_iMenuItem++;
        return getStartTag() + super.permittedItem(node) + getEndTag();
    }

    private String getStartTag() {
        return getStartTag(null);
    }

    private String getStartTag(String cls) {
        StringBuffer s = new StringBuffer("<div class=\"menuitem");
        if (cls != null)
            s.append(" ").append(cls);
        if (m_iMenuItem == 1)
            s.append(" first");
        s.append("\" >");
        return s.toString();
    }

    private String getEndTag() {
        return "</div>";
    }

    public String restrictedItem(Module node) {
        m_iMenuItem++;
        return getStartTag() + super.restrictedItem(node) + getEndTag();
    }

    public String chosenItem(Module node) {
        m_iMenuItem++;
        return getStartTag("selected") + super.chosenItem(node) + getEndTag();
    }
}
